package com.example.caoben_back.config;

import com.example.caoben_back.system.SystemPrompts;
import com.example.caoben_back.tool.Tools;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class CommonConfig {

    @Bean
    public ChatClient serviceChatClient(OllamaChatModel chatModel, ChatMemory chatMemory, Tools tools){
        return ChatClient
                .builder(chatModel)
                .defaultSystem(SystemPrompts.COMPREHENSIVE_SYSTEM_PROMPT)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        MessageChatMemoryAdvisor.builder(chatMemory).build()
                )
                .defaultTools(tools)
                .build();

    }

    //RestTemplate 是 Spring 提供的用于进行 HTTP 请求的模板类
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}